package com.dyh.quickdemo.biz;

import com.google.common.collect.Lists;

/*
订单相关是other
shop相关是others
*/
public enum QimenStylePlatform {

        TB("TB", "淘宝", (platform, shopPlatform) -> Shop.SHOP_PLATFORM_TAOBAO.equals(shopPlatform)),
        TM("TM", "天猫", (platform, shopPlatform) -> {
                return Lists.newArrayList(Shop.SHOP_PLATFORM_TMALL, Shop.SHOP_PLATFORM_TMALL_I18N, Shop.SHOP_PLATFORM_TMALL_SUPERMARKET_OFFLINE)
                        .contains(shopPlatform);
        }),
        CT("CT", "村淘", (platform, shopPlatform) -> Shop.PLATFORM_CUN_TAOBAO.equals(shopPlatform)),
        JD("JD", "京东", (platform, shopPlatform) ->
                Shop.PLATFORM_JOS.equals(platform)
        ),

        DD("DD", "当当", (platform, shopPlatform) -> false),//未对接

        PP("PP", "拍拍", (platform, shopPlatform) -> false),
        YX("YX", "易讯", (platform, shopPlatform) -> false),
        EBAY("EBAY", "ebay", (platform, shopPlatform) -> false),
        QQ("QQ", "QQ网购", (platform, shopPlatform) -> false),
        AMAZON("AMAZON", "亚马逊", (platform, shopPlatform) ->"AMAZON" .equals(shopPlatform)),
        SN("SN", "苏宁", (platform, shopPlatform) -> Shop.SHOP_PLATFORM_SUNING.equals(shopPlatform)),
        GM("GM", "国美", (platform, shopPlatform) -> false),
        WPH("WPH", "唯品会", (platform, shopPlatform) ->
                Lists.newArrayList(Shop.PLATFORM_VIP, Shop.PLATFORM_VIP_MP, Shop.PLATFORM_VIP_ZHIFA, Shop.PLATFORM_JITX).contains(platform)),
        JM("JM", "聚美", (platform, shopPlatform) -> false),
        LF("LF", "乐蜂", (platform, shopPlatform) -> false),
        MGJ("MGJ", "蘑菇街", (platform, shopPlatform) -> Shop.PLATFORM_MOGUJIE.equals(platform)),
        JS("JS", "聚尚", (platform, shopPlatform) -> false),
        PX("PX", "拍鞋", (platform, shopPlatform) -> false),
        YT("YT", "银泰", (platform, shopPlatform) -> false),
        YHD("YHD", "1号店", (platform, shopPlatform) -> false),
        VANCL("VANCL", "凡客", (platform, shopPlatform) -> false),
        YL("YL", "邮乐", (platform, shopPlatform) -> false),
        YG("YG", "优购", (platform, shopPlatform) -> false),
        ALIBABA("1688", "阿里巴巴", (platform, shopPlatform) -> Shop.SHOP_PLATFORM_ALIBABA.equals(platform)),
        POS("POS", "POS门店", (platform, shopPlatform) -> false),
        MIA("MIA", "蜜芽", (platform, shopPlatform) -> Shop.PLATFORM_MIYA.equals(platform)),
        GW("GW", "商家官网", (platform, shopPlatform) -> false),
        YJWD("YJWD", "云集微店", (platform, shopPlatform) -> Shop.PLATFORM_YUNJI.equals(platform)),
        DY("OTHER", "DY", (platform, shopPlatform) -> Shop.PLATFORM_FANGXINGOU.equals(platform)),
        PDD("PDD", "拼多多", (platform, shopPlatform) -> Shop.PLATFORM_PINDUODUO.equals(platform)),

        FALLBACK("OTHER", "其他", (platform, shopPlatform) -> true); //这个放在最后能被找到
        ;


        public String code;
        public String desc;
        private Matcher matcher;

        QimenStylePlatform(String code, String desc, Matcher matcher) {
                this.code = code;
                this.desc = desc;
                this.matcher = matcher;
        }

        public static QimenStylePlatform findOne(Shop shop){
                for (QimenStylePlatform qimenPlatform : QimenStylePlatform.values()) {
                    if (qimenPlatform.matcher.match(shop.getPlatform(),shop.getShopPlatform()))
                        return qimenPlatform;
                }
                return null;
        }

        public static QimenStylePlatform findOne(String platform,String shopPlatform){
                for (QimenStylePlatform qimenPlatform : QimenStylePlatform.values()) {
                        if (qimenPlatform.matcher.match(platform,shopPlatform))
                                return qimenPlatform;
                }
                return null;
        }

        @FunctionalInterface
        interface Matcher {
                boolean match(String platform, String shopPlatform);
        }

//        public static void main(String[] args) {
//                Shop shop1 = new Shop();
//                shop1.setPlatform("TAOBAO");
//                shop1.setShopPlatform("TAOBAO");
//
//                Shop shop2 = new Shop();
//                shop2.setPlatform("TAOBAO");
//                shop2.setShopPlatform("TMALL");
//
//                Shop shop3 = new Shop();
//                shop3.setPlatform("FANGXINGOU");
//
//                Shop shop4 = new Shop();
//                shop4.setPlatform("adwawd");
//
//                Shop shop5 = new Shop();
//                shop4.setPlatform("PINDUODUO");
//
//                QimenStylePlatform r1 = QimenStylePlatform.findOne(shop1);
//                QimenStylePlatform r2 = QimenStylePlatform.findOne(shop2);
//                QimenStylePlatform r3 = QimenStylePlatform.findOne(shop3);
//                QimenStylePlatform r4 = QimenStylePlatform.findOne(shop4);
//                QimenStylePlatform r5 = QimenStylePlatform.findOne(shop5);
//
//                System.out.println();
//        }

        public static void main(String[] args) {
                String shippingMemo = "11111";
                String[]msgs = new String[]{"","","",""};
                int start = 0;
                for (int i =0;i<shippingMemoLimit.length;i++) {
                        int end = start+shippingMemoLimit[i];
                        msgs[i] = shippingMemo.substring(start,Math.min(end,shippingMemo.length()));
                        start = end;
//                        if (start>=shippingMemo.length())
//                                break;
                }

                System.out.println();

        }

        private static int shippingMemoLimit[] = {127,33,33,33};

}